﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using Axis.Web.Administrator.Global;
using Axis.Dao.Research;
using Axis.BusinessObject.Core;
using System.Web.Script.Serialization;
using Axis.BusinessObject.Research;
namespace Axis.Web.Views.Project.Service
{
    /// <summary>
    /// Summary description for ServeyService
    /// </summary>
    public class ServeyService : IHttpHandler, IReadOnlySessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            string action = context.Request["Action"];
            string output = string.Empty;
            switch (action)
            {
                case "INSERT":
                case "UPDATE":
                case "DELETE":
                    output = UpdateQuestionPath(context);
                    break;              
            }
            context.Response.Write(output);
        }
        protected string UpdateQuestionPath(HttpContext context)
        {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            CMemberList member = new CMemberList();
            if (context.Session["MEMBERINFO"] != null)
                member = context.Session["MEMBERINFO"] as CMemberList;
            CProjectUI questionPathUI = new CProjectUI(member);

            if (context.Request["pCaptcha"] != null)
            {
                string pCaptcha = context.Request["pCaptcha"];
                bool captchaValidate = CSecurity.ValidateMD5HashData(pCaptcha, CSecurity.CAPTCHA_CODE);
                if (captchaValidate == false)
                {
                    CSecurity.CAPTCHA_CODE = null;
                    CApplicationMessage result = new CApplicationMessage();
                    result.Result = 0;
                    result.Code = "CAPTCHA_INVALID";
                    result.IsSuccessfull = false;
                    result.Description = "Mã xác nhận không đúng.";
                    return new JavaScriptSerializer().Serialize(result);
                }
            }
            return questionPathUI.SaveServey(context);
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}